<?php
class ReturnService extends BaseDbService
{
	public function __construct()
	{
		$this->dao				= new ReturnDao();
	}
	
	public function getReturnedMoney($userId,$status='')
	{
		$condition['fields'] 					= 'sum(money) as money';
		$condition['where']['expression'] 		= "user_id = :user_id";
		$condition['where']['value']['user_id'] = $userId;
		if($status!='')
		{
			$condition['where']['expression'] 		.= " AND status = :status";
			$condition['where']['value']['status'] 	= $status;
		}
		$tmp 	= $this->dao->fetchRows($condition);
		$ret	= $tmp[0]['money'];
		if(empty($ret))
		{
			$ret	= 0;
		}
		return $ret;
	}
	
	public function getTotalMoneyByPeriod($startDate='',$endDate='', $status=1)
	{
		$condition['where']['expression']	= 'status= '.$status;
		if($startDate!='')
		{
			 $condition['where']['expression']	.= ' and check_time >= "'.$startDate.' 00:00:00"';
		}
		if($endDate!='')
		{
			 $condition['where']['expression']	.= ' and check_time <= "'.$endDate.' 23:59:59"';
		}
		$condition['fields'] 	= 'sum(money) as money';
		
		$tmp 					= $this->dao->fetchRows($condition);
		if(empty($tmp[0]['money']))
		{
			return 0;
		}
		return $tmp[0]['money'];
	}
}
?>